package com.huike.review.controller;

import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController()
@Slf4j
public class RevieController {
    @Autowired
    private ReviewService reviewService;

    //新增接口1：    /review/saveData/吴思远/18/男
    @GetMapping("/review/saveData/{name}/{age}/{sex}")
    public AjaxResult save1(@PathVariable String name,
                            @PathVariable String age,
                            @PathVariable String sex){
        reviewService.insetBysan(name,age,sex);
        return new AjaxResult(200,"成功插入:1条数据");
    }

    //新增接口2：
    @PostMapping("/review/saveData")
    public AjaxResult save2(@RequestBody Review review){
        reviewService.insetByReview(review);
        return new AjaxResult(200,"成功插入:1条数据");
    }

    //--3--修改：
    @PostMapping("/review/update")
    public AjaxResult update1(@RequestBody Review review){
        reviewService.updateByReview(review);
        return new AjaxResult(200,"修改成功");
    }

    //--4--删除接口：
    @DeleteMapping("/review/remove/{id}")
    public AjaxResult deleteById(@PathVariable Long id){
        reviewService.deleteById(id);
        return new AjaxResult(200,"成功删除:1条数据");
    }

    //--5--单条件查询，根据id来查询数据：/review/getById?id=1
    @GetMapping("/review/getById")
    public AjaxResult selectById(Long id){
        Review review=reviewService.selectById(id);
        return new AjaxResult(200,"操作成功",review);
    }

    //--5--分页查询：接口名：/review/getDataByPage?pageNum=1&pageSize=10
    @GetMapping("/review/getDataByPage")
    public TableDataInfo selectBypage(Integer pageNum, Integer pageSize){
        TableDataInfo tableDataInfo=reviewService.selectBypage(pageNum,pageSize);
        tableDataInfo.setMsg("查询成功");
        tableDataInfo.setCode(200);
        return tableDataInfo;
    }
}
